% fname: routing_oddeven__sel_nop__topology_8x8__.m
% ./noxim -routing oddeven -sel nop -dimx 8 -dimy 8  -sim 10000 -warmup 2000 -size 8 8 -buffer 4 -hs 6 0.2 -hs 7 0.2 -hs 14 0.2 -hs 15 0.2 

function [max_pir, max_throughput, min_delay] = routing_oddeven__sel_nop__topology_8x8__(symbol)

data = [
%             pir      avg_delay     throughput      max_delay       rpackets         rflits
           0.0015        19.7562      0.0127833             77            767           6136
           0.0015        19.1365      0.0130191            135            769           6145
           0.0015        20.3993      0.0138136            102            814           6520
           0.0015         19.834      0.0123545             79            753           6029
           0.0015         19.774      0.0130657             73            770           6167
           0.0015        18.2951      0.0133068            101            732           5855
           0.0015        20.8929      0.0135366            165            784           6281
           0.0015        20.0859      0.0136987             86            768           6137
           0.0015        19.3705      0.0135568             67            745           5965
           0.0015        20.0784      0.0135979             89            816           6527
           0.0015        18.9034      0.0127854             85            766           6137
           0.0015        19.2647      0.0127729             77            767           6131
           0.0015        17.8992      0.0120328            109            734           5872
           0.0015        21.2306      0.0135229            148            811           6491
           0.0015        20.3567      0.0137646             87            827           6607
           0.0015         18.851       0.012256             71            772           6177
           0.0015        20.0465      0.0131996            105            753           6019
           0.0015        19.3742      0.0121149            102            751           6009
           0.0015        20.0818      0.0120146            118            721           5767
           0.0015        19.9747      0.0129477             84            712           5697
           0.0017        20.1547       0.013875             75            834           6660
           0.0017        20.5565      0.0144978            121            841           6727
           0.0017        23.2239      0.0146915            148            911           7287
           0.0017        21.3908      0.0144146            115            865           6919
           0.0017        21.2098      0.0141391            119            877           7013
           0.0017        21.9217      0.0136069            127            843           6749
           0.0017        21.3856      0.0140694            146            887           7091
           0.0017         20.936      0.0140583            117            844           6748
           0.0017        20.4475      0.0132828             95            809           6482
           0.0017        20.8772      0.0142034            101            839           6704
           0.0017        20.1425      0.0135544             94            842           6723
           0.0017        20.6564      0.0140726            117            873           6980
           0.0017        20.3548      0.0142396            141            854           6835
           0.0017        20.5855      0.0144652            104            883           7059
           0.0017        20.1988      0.0144852            102            855           6837
           0.0017        19.5686      0.0127383            121            816           6522
           0.0017        21.6149      0.0140813             94            888           7097
           0.0017         20.453      0.0138353             91            872           6973
           0.0017        20.8922      0.0151404            105            863           6904
           0.0017        22.0491      0.0156183            109            875           6997
           0.0019        22.2824      0.0151673            114            942           7523
           0.0019        22.6908      0.0157837            164            993           7955
           0.0019        23.3039       0.015584            119            951           7605
           0.0019        24.0885      0.0163972            151           1017           8133
           0.0019        21.1154      0.0162697            130            927           7419
           0.0019         22.854      0.0149901            101            945           7555
           0.0019         23.029       0.015877             93           1000           8002
           0.0019        22.9537      0.0162746            198            993           7942
           0.0019        21.9862       0.016131            115           1016           8130
           0.0019        24.9525      0.0165758            167           1011           8089
           0.0019        22.6381      0.0151726            148            956           7647
           0.0019        22.3085      0.0162602            135            992           7935
           0.0019        22.1761      0.0142401             92            897           7177
           0.0019        24.7594      0.0161475            253            985           7880
           0.0019        21.5066      0.0158972            115            985           7885
           0.0019        23.0515      0.0163373            124           1029           8234
           0.0019        24.5312      0.0155246            141            947           7576
           0.0019        26.2241      0.0168206            185           1044           8343
           0.0019        22.9289       0.016131            121            999           8001
           0.0019        21.1931      0.0156393             99            953           7632
           0.0021        24.5377      0.0165566            155           1060           8477
           0.0021        24.4042      0.0164648            170           1054           8430
           0.0021        25.3985      0.0172817            375           1089           8710
           0.0021        25.8091      0.0176721            218           1079           8624
           0.0021        23.4159      0.0167883            122           1041           8327
           0.0021        23.7212      0.0177639            118           1119           8953
           0.0021        22.8134      0.0172679             88           1088           8703
           0.0021        23.3954      0.0167024            146           1052           8418
           0.0021        27.6386      0.0177123            319           1115           8927
           0.0021        24.7774      0.0179809            143           1060           8487
           0.0021        25.7869      0.0168948            240           1065           8515
           0.0021        28.9268      0.0179792            245           1079           8630
           0.0021        24.7629      0.0166172            169           1063           8508
           0.0021        25.1487      0.0178175            135           1123           8980
           0.0021        25.4055      0.0166329            179           1048           8383
           0.0021        25.9169      0.0169063            264           1083           8656
           0.0021        26.8574      0.0170766            222           1059           8470
           0.0021        26.4055      0.0179087            172           1127           9026
           0.0021          24.63      0.0164286            166           1035           8280
           0.0021        23.8739      0.0180121            113           1118           8934
           0.0023          28.75      0.0193286            289           1200           9587
           0.0023        28.1488       0.019619            177           1216           9731
           0.0023        26.2747      0.0192807            206           1176           9409
           0.0023        27.1786      0.0185469            228           1187           9496
           0.0023        29.2401      0.0189725            193           1116           8955
           0.0023        29.8164      0.0186387            291           1193           9543
           0.0023        30.3463      0.0187103            236           1178           9430
           0.0023         28.029      0.0183418            191           1173           9391
           0.0023        28.0269      0.0189087            165           1191           9530
           0.0023        26.1968      0.0177559            199           1138           9091
           0.0023        25.2924      0.0196956            233           1221           9769
           0.0023        27.7004      0.0189201            263           1155           9233
           0.0023        26.0368      0.0182793            228           1170           9359
           0.0023        30.2119      0.0202049            177           1232           9860
           0.0023        30.7436      0.0196191            298           1256          10045
           0.0023        27.7962      0.0193226            203           1197           9584
           0.0023         26.474      0.0183516            164           1175           9396
           0.0023        29.3336      0.0189365            248           1193           9544
           0.0023        28.4558      0.0189219            182           1211           9688
           0.0023        25.4393      0.0181607            146           1145           9153
           0.0025        28.9571      0.0186055            155           1190           9526
           0.0025        26.8634      0.0190754            136           1201           9614
           0.0025        27.8411      0.0198968            175           1252          10028
           0.0025        35.2262      0.0201738            269           1291          10329
           0.0025        29.6518      0.0202917            221           1278          10227
           0.0025        37.5938      0.0210615            356           1327          10615
           0.0025         33.874       0.020666            272           1262          10085
           0.0025        30.5965      0.0197889            156           1207           9657
           0.0025        32.6611      0.0199345            228           1257          10047
           0.0025        35.9287      0.0209464            294           1319          10557
           0.0025        33.9922      0.0203909            552           1286          10277
           0.0025        46.4487      0.0213027            864           1364          10907
           0.0025        28.1385      0.0199688            166           1278          10224
           0.0025        30.0589      0.0205524            182           1274          10194
           0.0025        36.4745      0.0205302            320           1273          10183
           0.0025        44.5615      0.0218535            355           1398          11189
           0.0025        40.6407      0.0207639            588           1308          10465
           0.0025        32.0902      0.0210766            207           1308          10454
           0.0025        30.8789      0.0201865            230           1272          10174
           0.0025        30.6794       0.020041            344           1282          10261
           0.0027          32.27      0.0218155            327           1374          10995
           0.0027        35.1058      0.0220635            353           1390          11120
           0.0027        34.5285      0.0213848            241           1370          10949
           0.0027        62.1596      0.0224254            968           1391          11123
           0.0027        42.1853       0.021871            481           1376          11023
           0.0027        34.5232      0.0208516            332           1334          10676
           0.0027        35.8862      0.0213373            301           1344          10754
           0.0027        34.6247      0.0220655            276           1391          11121
           0.0027        44.0674        0.02225            555           1380          11036
           0.0027        37.4861       0.021875            489           1401          11200
           0.0027        39.9601      0.0218591            281           1377          11017
           0.0027        35.0167       0.021877            212           1379          11026
           0.0027        37.4346      0.0219444            418           1383          11060
           0.0027        39.8388      0.0229335            357           1421          11375
           0.0027        39.0561      0.0223452            365           1407          11262
           0.0027        40.3782      0.0218398            333           1396          11182
           0.0027        37.6653       0.022621            343           1425          11401
           0.0027        49.2985      0.0217361           1061           1370          10955
           0.0027        47.4178      0.0220527            730           1412          11291
           0.0027        36.0314      0.0222202            295           1400          11199
           0.0029        46.3684      0.0242897            480           1531          12242
           0.0029        50.0556      0.0230371            619           1474          11795
           0.0029         39.727      0.0243492            315           1535          12272
           0.0029        66.0193      0.0242188            876           1552          12400
           0.0029        45.5786       0.023332            480           1495          11946
           0.0029        60.0686      0.0236797           1048           1517          12124
           0.0029        44.1076      0.0235527            375           1506          12059
           0.0029        49.9159      0.0235879            960           1511          12077
           0.0029        47.9174      0.0240298            390           1514          12111
           0.0029        50.3764      0.0233274            657           1469          11757
           0.0029        44.7089      0.0237871            556           1522          12179
           0.0029        45.0338         0.0235            513           1481          11844
           0.0029        36.3769      0.0236726            312           1491          11931
           0.0029        50.2618      0.0231738            658           1482          11865
           0.0029         46.201      0.0239961            473           1537          12286
           0.0029        55.0548      0.0233848            821           1496          11973
           0.0029        64.7982      0.0243075            841           1531          12251
           0.0029        44.6209          0.023            438           1472          11776
           0.0029        52.9771      0.0225605           1049           1444          11551
           0.0029        37.5726      0.0224766            393           1439          11508
           0.0031        89.9553      0.0255625           1177           1634          13088
           0.0031        47.5575      0.0245723            543           1573          12581
           0.0031         68.689      0.0245352            635           1569          12562
           0.0031        94.6877      0.0255273            873           1633          13070
           0.0031        74.1101      0.0238175           1905           1499          12004
           0.0031        75.8297      0.0247441           1033           1585          12669
           0.0031        62.2141      0.0250938           1105           1607          12848
           0.0031         45.205      0.0241621            541           1546          12371
           0.0031        66.9537      0.0254476            926           1577          12622
           0.0031        50.8776      0.0240059            451           1536          12291
           0.0031        78.3177       0.024582           1856           1574          12586
           0.0031         60.176      0.0245098            765           1568          12549
           0.0031        81.2862      0.0258274           1831           1628          13017
           0.0031        70.2626      0.0261389            801           1645          13174
           0.0031         68.692      0.0252852           1168           1617          12946
           0.0031        54.8439      0.0255312            712           1634          13072
           0.0031        70.9018      0.0249688            817           1598          12784
           0.0031        88.0812      0.0248398           1352           1589          12718
           0.0031        53.4019      0.0235742            644           1508          12070
           0.0031        99.5521      0.0254727            973           1632          13042
           0.0033        94.2014      0.0248848           1689           1594          12741
           0.0033        169.344      0.0253988           2309           1600          12801
           0.0033        164.515      0.0263496           2467           1687          13491
           0.0033        100.172      0.0261934           1119           1676          13411
           0.0033         152.33      0.0262051           2324           1677          13417
           0.0033        143.477      0.0259121           1961           1658          13267
           0.0033        136.873      0.0258359           2501           1655          13228
           0.0033        92.0266      0.0257949           1382           1652          13207
           0.0033        149.711      0.0260488           3366           1667          13337
           0.0033        109.351      0.0264316           1483           1691          13533
           0.0033        157.032      0.0274544           2664           1728          13837
           0.0033         149.27      0.0260586           1500           1668          13342
           0.0033        90.8368      0.0256406           1391           1642          13128
           0.0033        113.543      0.0256992           1444           1645          13158
           0.0033        142.442      0.0262579           1702           1653          13234
           0.0033        156.902      0.0263105           2187           1684          13471
           0.0033        200.363      0.0259062           3580           1658          13264
           0.0033        100.377      0.0262559           1147           1681          13443
           0.0033        144.892      0.0265918           1747           1702          13615
           0.0033        91.9302      0.0264258           1075           1691          13530
];

rows = size(data, 1);
cols = size(data, 2);

data_delay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+1);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_delay = [data_delay; data(ifirst, 1:cols-5), avg ci];
end

figure(1);
hold on;
plot(data_delay(:,1), data_delay(:,2), symbol);

data_throughput = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+2);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_throughput = [data_throughput; data(ifirst, 1:cols-5), avg ci];
end

figure(2);
hold on;
plot(data_throughput(:,1), data_throughput(:,2), symbol);

data_maxdelay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+3);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_maxdelay = [data_maxdelay; data(ifirst, 1:cols-5), avg ci];
end

figure(3);
hold on;
plot(data_maxdelay(:,1), data_maxdelay(:,2), symbol);


%-------- Saturation Analysis -----------
slope=[];
for i=2:size(data_throughput,1),
    slope(i-1) = (data_throughput(i,2)-data_throughput(i-1,2))/(data_throughput(i,1)-data_throughput(i-1,1));
end

for i=2:size(slope,2),
    if slope(i) < (0.95*mean(slope(1:i)))
        max_pir = data_throughput(i, 1);
        max_throughput = data_throughput(i, 2);
        min_delay = data_delay(i, 2);
        break;
    end
end
